package cn.lizemin.mybatisplus;

import cn.lizemin.mybatisplus.entity.User;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;

import java.util.*;

/**
 * @author: lizemin
 * @version: 1.0
 */
public class MyDemo {
    @Test
    public void test1(){
        String str = "12345";
        StringBuilder sb = new StringBuilder(str);
        StringBuilder reverse = sb.reverse();
        System.out.println(reverse);

    }

    @Test
    public void test2(){
        //list去重
        ArrayList<Object> arrayList = new ArrayList<>();
        arrayList.add(23);
        arrayList.add(22);
        arrayList.add(23);
        HashSet<Object> set = new HashSet<>();
        set.addAll(arrayList);
        arrayList.clear();
        arrayList.addAll(set);
        System.out.println(arrayList);
    }

    @Test
    public void test3(){
        HashSet<Integer> integers = new HashSet<>();
        integers.add(12);
        integers.add(1);
        integers.add(13);
        integers.add(16);
        /*Iterator<Integer> iterator = integers.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());

        }*/
        System.out.println(integers);

    }

    @Test
    public void test4(){
        User user = new User();
        user.setName("dog");
        user.setAge(25);

        User user2 = new User();
        user2.setName("dog");
        user2.setAge(25);

        User user3 = new User();
        user3.setName("dog");
        user3.setAge(25);

        HashSet<User> users = new HashSet<>();
        users.add(user);
        users.add(user2);
        users.add(user3);

        System.out.println(users.size());
        users.forEach(System.out::println);

//        System.out.println(user.equals(user2));

    }

    @Test
    public void test5(){
        HashMap<String, String> map = new HashMap<>();
        map.put("key1","a");
        map.put("key2","a");
        map.put("key3","c");
        map.put("key4","a");
        Collection<String> values = map.values();
        boolean exists = values.contains("c");
        System.out.println(exists);

    }

    @Test
    public void test7(){
        String str = "abc";

        /*StringBuilder sb = new StringBuilder(str);
        System.out.println(sb.reverse());*/
        char[] str_arr = str.toCharArray();
//        System.out.println(str_arr);
        ArrayList<Character> list = new ArrayList<>();
        for (int i = str_arr.length - 1; i >= 0; i--) {
            list.add(str_arr[i]);
        }
        //数组转字符串
        /*Object[] objects = list.toArray();
        StringUtils
        System.out.println(s);*/
    }

    @Test
    public void test8(){
        //统计list重复元素的个数
        ArrayList<Integer> list = new ArrayList<>();
        list.add(12);
        list.add(22);
        list.add(32);
        list.add(22);

        HashMap<Integer, Integer> hm = new HashMap<>();
        list.forEach(num -> {
            Integer count = hm.get(num);
            System.out.println(count);//null
            hm.put(num,count == null ? 1 : ++count);
        });

        System.out.println(hm);

        /*for (Integer integer : list) {
            hm.put("count")

        }*/






    }




}
